package com.hongxun.budget.ui.dialog;

import android.text.TextUtils;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;

import com.hongxun.budget.R;
import com.hongxun.interfaces.ClickListener;

import butterknife.BindView;
import butterknife.OnClick;

/**
 * Created by admin on 2018/7/17.
 */

public class NoticeDialog extends BaseCenterFragmentDialog {
    @BindView(R.id.title)
    TextView titleTv;
    @BindView(R.id.content)
    TextView contentTv;
    String title, content, confirm, cancel;
    @BindView(R.id.cancel)
    Button cancelButton;
    @BindView(R.id.confirm)
    Button confirmButton;
    ClickListener confirmListener;
    ClickListener cancelListener;

    @Override
    protected int getLayoutId() {
        return R.layout.dialog_notice;
    }

    @Override
    protected void initViews() {
        if (!TextUtils.isEmpty(title)) titleTv.setText(title);
        if (!TextUtils.isEmpty(content)) contentTv.setText(content);
        if (!TextUtils.isEmpty(cancel)) {
            cancelButton.setVisibility(View.VISIBLE);
            cancelButton.setText(cancel);
        }
        if (!TextUtils.isEmpty(confirm)) confirmButton.setText(confirm);
    }

    public NoticeDialog setTitle(String title) {
        this.title = title;
        if (titleTv != null) titleTv.setText(title);
        return this;
    }

    public NoticeDialog setMsg(String msg) {
        this.content = msg;
        if (contentTv != null) titleTv.setText(content);
        return this;
    }

    public NoticeDialog setCancelButton(String cancel, ClickListener cancelListener) {
        this.cancelListener = cancelListener;
        this.cancel = cancel;
        if (cancelButton != null) cancelButton.setText(cancel);
        if (cancel == null && cancelButton != null) cancelButton.setVisibility(View.VISIBLE);
        return this;
    }

    public NoticeDialog setConfirmButton(String confirm, ClickListener confirmListener) {
        this.confirmListener = confirmListener;
        this.confirm = confirm;
        if (confirmButton != null && confirmButton != null) confirmButton.setText(confirm);
        return this;
    }

    @OnClick({R.id.cancel, R.id.confirm})
    public void onViewClicked(View view) {
        switch (view.getId()) {
            case R.id.cancel:
                if (cancelListener != null) {
                    cancelListener.click();
                }
                break;
            case R.id.confirm:
                if (confirmListener != null) {
                    confirmListener.click();
                }
                break;
        }
        dismiss();
    }

}
